package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.pay.body.PayRecordsBody;
import com.xinfu.newproject.bean.paycost.bean.GetBillByTypeBean;
import com.xinfu.newproject.bean.paycost.bean.QueryTypesBean;
import com.xinfu.newproject.bean.paycost.body.GetBillByTypeBody;
import com.xinfu.newproject.bean.paycost.body.QueryTypesBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.pay_cost.PayCostModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class PayCostPresenter {
    private IView.IPayCostView mIPayCostView;
    private IView.IPayRecordsView mPayRecordsView;

    private PayCostModel mPayCostModel;

    public PayCostPresenter(IView.IPayCostView iPayCostView) {
        this.mIPayCostView = iPayCostView;
        mPayCostModel = new PayCostModel();
    }

    public PayCostPresenter(IView.IPayRecordsView iPayRecordsView) {
        this.mPayRecordsView = iPayRecordsView;
        mPayCostModel = new PayCostModel();
    }

    /**
     *
     */
    public void queryTypes() {
        mIPayCostView.showProgress();
        QueryTypesBody queryTypesBody = new QueryTypesBody(mIPayCostView.header());

        mPayCostModel.queryTypes(queryTypesBody, new MyCallBack<QueryTypesBean>() {
            @Override
            public void onSuccess(QueryTypesBean queryTypesBean) {
                mIPayCostView.hideProgress();
                if (queryTypesBean.isSuccess()) {
                    mIPayCostView.getData(queryTypesBean);
                } else {
                    mIPayCostView.showToast(queryTypesBean.getMessage());
                }
            }

            @Override
            public void onError(String header, String message) {
                mIPayCostView.hideProgress();
                mIPayCostView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIPayCostView.closeDispose(disposable);
            }
        });


    }

    /**
     *
     */
    public void getBillsByType() {
        mIPayCostView.showProgress();
        GetBillByTypeBody getBillByTypeBody = new GetBillByTypeBody(mIPayCostView.header(), mIPayCostView.roomId(), mIPayCostView.type(), mIPayCostView.cusOrRent());

        mPayCostModel.getBillsByType(getBillByTypeBody, new MyCallBack<GetBillByTypeBean>() {
            @Override
            public void onSuccess(GetBillByTypeBean getBillByTypeBean) {
                mIPayCostView.hideProgress();
                if (getBillByTypeBean.isSuccess()) {
                    mIPayCostView.getData(getBillByTypeBean);
                } else {
                    mIPayCostView.showToast(getBillByTypeBean.getMessage());
                }
            }

            @Override
            public void onError(String header, String message) {
                mIPayCostView.hideProgress();
                mIPayCostView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIPayCostView.closeDispose(disposable);
            }
        });
    }

    /**
     * 缴费记录
     */
    public void payRecords() {

        mPayRecordsView.showProgress();

        PayRecordsBody payRecordsBody = new PayRecordsBody(mPayRecordsView.header(), mPayRecordsView.userId());

        mPayCostModel.payRecords(payRecordsBody, new MyCallBack<String>() {
            @Override
            public void onSuccess(String payRecordsBean) {
                mPayRecordsView.hideProgress();
//                if (payRecordsBean.isSuccess()) {
//                    mPayRecordsView.getMsg(payRecordsBean);
//                } else {
//                    mPayRecordsView.showToast(payRecordsBean.getMessage());
//                }
                mPayRecordsView.getMsg(payRecordsBean);
//                mPayView.showToast(payBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {
                mPayRecordsView.hideProgress();
                mPayRecordsView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mPayRecordsView.closeDispose(disposable);
            }
        });


    }
}
